<?php
function match_get_ids($id) {
	$sql = 'SELECT ID_equipe_d,ID_equipe_e,ID FROM `match` WHERE ID='.$id.';';
	return query($sql);
}

function match_journee($id) {//donne tous les matchs d'une journee
	$sql = 'SELECT * FROM `match` WHERE ID_journee='.$id.';';
	return query($sql);
}

function match_get_next($all=false) {
        $current_date = time();
        $sql = 'SELECT * FROM `match` WHERE date >= '.$current_date.' ORDER BY date ';
		if(!$all) $sql .= 'LIMIT 1;';
        return query($sql);
}

function match_get_past() {
        $current_date = time();
        $sql = 'SELECT * FROM `match` WHERE date <= '.$current_date.' AND score_equipe_d=-1 ORDER BY date ;';
        return query($sql);
}

function match_get_last($all=false) {
        $sql = 'SELECT * FROM `match` ORDER BY date DESC ';
        if(!$all) $sql .= 'LIMIT 1;';
        return query($sql);
}
function match_existe($id_eq,$idj) {
		$sql = 'SELECT * FROM `match` WHERE (ID_equipe_d='.$id_eq.' OR ID_equipe_e='.$id_eq.') AND ID_journee='.$idj.';';
        return query($sql);
}


function match_creer($id_eqd,$id_eqe,$idj,$date) {
		$sql = "INSERT INTO `match` VALUES ('','$id_eqd','$id_eqe','\-1','','$idj','$date');";
        return query($sql);
}

function match_modif_date($id_m,$date) {
		$sql = 'UPDATE `match` SET date = '.$date.' WHERE ID ='.$id_m.';';
        return query($sql);
}

function match_resultat($id_m,$score_eqd,$score_eqe) {
		$sql = 'UPDATE `match` SET score_equipe_d = '.$score_eqd.' , score_equipe_e = '.$score_eqe.' WHERE ID ='.$id_m.';';
        return query($sql);
}

function delete_all_match(){
		$sql = 'DELETE FROM `match`;'; 
		return query($sql);
}